from typing import List, Optional
from app.repositories.sponsor_contact_repo import SponsorContactRepo
from app.schema.sponsor_contact_schema import SponsorContactItem

class SponsorContactService:
    def __init__(self, repo: SponsorContactRepo):
        self.repo = repo

    def list_contacts_by_sponsor_id(
        self,
        sponsor_id: int,
        kc: Optional[bool] = None,
        inv: Optional[bool] = None,
    ) -> List[SponsorContactItem]:
        contacts = self.repo.get_by_sponsor_id(sponsor_id, kc, inv)
        return [SponsorContactItem.from_orm(c) for c in contacts]

    def get_contact(self, contact_id: int) -> Optional[SponsorContactItem]:
        c = self.repo.get_by_id(contact_id)
        return SponsorContactItem.from_orm(c) if c else None